using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace FastFoodToNight.Models.Mapping
{
    public class HoaDonMap : EntityTypeConfiguration<HoaDon>
    {
        public HoaDonMap()
        {
            // Primary Key
            this.HasKey(t => t.mahoadon);

            // Properties
            this.Property(t => t.nguoilap)
                .IsRequired()
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("HoaDon");
            this.Property(t => t.mahoadon).HasColumnName("mahoadon");
            this.Property(t => t.ngaylap).HasColumnName("ngaylap");
            this.Property(t => t.maddh).HasColumnName("maddh");
            this.Property(t => t.tongtien).HasColumnName("tongtien");
            this.Property(t => t.nguoilap).HasColumnName("nguoilap");

            // Relationships
            this.HasRequired(t => t.BanQuanLy)
                .WithMany(t => t.HoaDons)
                .HasForeignKey(d => d.nguoilap);
            this.HasRequired(t => t.DonDatHang)
                .WithMany(t => t.HoaDons)
                .HasForeignKey(d => d.maddh);

        }
    }
}
